package com.zhang.warehouse.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.zhang.warehouse.entity.WareInfo;
import com.zhang.warehouse.mapper.WareInfoMapper;
import com.zhang.warehouse.service.IWareInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Map;

/**
 * <p>
 * 仓库信息 服务实现类
 * </p>
 *
 * @author 创世神
 * @since 2023-10-13
 */
@Service
public class WareInfoServiceImpl extends ServiceImpl<WareInfoMapper, WareInfo> implements IWareInfoService {

    @Override
    public IPage getWareInfoListPage(Integer pageNum, Integer pageSize, Map<String, Object> wareInfoSearchDto) {
        QueryWrapper<WareInfo> wrapper = new QueryWrapper<>();
        String value = String.valueOf(wareInfoSearchDto.get("searchValue"));
       if (!StrUtil.isEmpty(value) ){
           wrapper.eq("id",value)
                   .or().like("name",value)
                   .or().like("address",value)
                   .or().eq("areacode",value);
       }
        Page<WareInfo> page = this.page(new Page<>(pageNum, pageSize), wrapper);
        return page;
    }

    @Override
    public BigDecimal getFreightByAddressId(Long addressId) {
//        TODO 运费的计算
        BigDecimal bigDecimal = new BigDecimal(10);
        return bigDecimal;
    }
}
